<?php
/*
 * @author Carlos Roberto Alvarez Muñoz <ingcram@gmail.com>
 */
Load::models('banners');
class BannerController extends AppController {

    public function index($page=1) 
    {
	$banners = new Banners();
        
        $this->banners = $banners->getAll($page);                	               
    }
    
    public function crear()
    {
        if(Input::hasPost('banners'))
       {	       
	        
            $banner = new Banners(); 	        
            if($banner->guardar())
            {
                Flash::success('Operación exitosa');				
            }else Flash::error($banner->error);			        	        		        
    						
        }        
    }
    
    public function editar($banner_id)
    {
        $banner = new Banners();
		
        if(Input::hasPost('banners')){
 
            if($banner->actualizar(Input::post('banners'))){
            	
                Flash::valid('Banner actualizado correctamente');            
                return Router::redirect();
                
            } else {
                Flash::error('El Banner no pudo ser actualizado');
            }
            
        }else  $this->banners = $banner->getBanner((int)$banner_id);                                    
    }
    
    public function borrar($banner_id)
    {
        $banner = new Banners();
        if ($banner->borrar((int)$banner_id)) {
                Flash::valid('Banner borrado con exito');
        }else{
                Flash::error('Banner no pudo ser borrado'); 
        }         
        return Router::redirect();
        
    }
    
}
